package com.hexb.smh.config;

import com.hexb.core.config.WebConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

/**
 * @author : hexb
 */
@Configuration
public class SmhWebConfig extends WebConfiguration {

    @Autowired
    private ActivatedInterceptor activatedInterceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(activatedInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/v2/api-docs",
                        "/webjars/**",
                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/error",
                        "/client/login",
                        "/client/active",
                        "/client/logout",
                        "/management/login",
                        "/management/active",
                        "/management/logout",
                        "/management/verificationCode"
                );
        super.addInterceptors(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/avatar/**")
                .addResourceLocations("classpath:/static/avatar/");

        registry.addResourceHandler("/template/**")
                .addResourceLocations("classpath:/static/template/");

        registry.addResourceHandler("/assets/**")
                .addResourceLocations("classpath:/static/assets/");

        registry.addResourceHandler("/brands/**")
                .addResourceLocations("classpath:/static/brands/");


        registry.addResourceHandler("/client/avatar/**")
                .addResourceLocations("classpath:/static/avatar/");

        registry.addResourceHandler("/client/assets/**")
                .addResourceLocations("classpath:/static/assets/");

        registry.addResourceHandler("/client/brands/**")
                .addResourceLocations("classpath:/static/brands/");
        super.addResourceHandlers(registry);
    }


}
